package pkg.payup;

import java.util.ArrayList;
import java.util.List;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class PayUPActivity extends Activity {
	
	//Declarations
	Account[] accounts;
	String domainType = "com.google";
	//Context context;
	List<String> accountNames = new ArrayList<String>();
	String AuthToken = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //context = getApplicationContext();
        if (AuthToken == null) {chooseAccount(); }
    }
    
    
    public void onMenuClickAccounts(View v) {
    	chooseAccount();
    }
    
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
    
    
    public void onSelect() {
    	//get references to radio buttons
    	//accounts.setAccount(get the text value of the selected radio sub menu item);   	
    }
    
    
    private void chooseAccount() {
    	//get all accounts in the device's central registry with specified type.
    	accounts = AccountManager.get(getApplicationContext()).getAccountsByType(domainType);
    	if (accounts.length > 0) {
    		for (Account account : accounts) { accountNames.add(account.name); Toast.makeText(getApplicationContext(), account.name, Toast.LENGTH_SHORT).show();}
    	ListView accountList = (ListView) findViewById(R.layout.list_item);
    	accountList.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, accountNames));
    	//accountList.setOnItemClickListener(new OnItemClickListener(){
    	//       @Override
    	//        public void onItemClick(AdapterView<?> parent, View view, int pos, long id){
    	         // checkAccount(accounts[pos]);
    	//        }
    	//    });	
        			}
   
    }
    
    
}